package cn.itcast.account.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

@LocalTCC
public interface AccountTccService {

    /**
     * 扣款
     *
     * @param userId 用户id
     * @param money  扣款金额
     */
    @TwoPhaseBusinessAction(name = "deduct" , commitMethod = "confirm", rollbackMethod = "cancel")
    void deduct(@BusinessActionContextParameter(paramName = "userId") String userId,
                @BusinessActionContextParameter(paramName = "money") int money);

    /**
     * 确认扣款
     *
     */
    boolean confirm(BusinessActionContext businessActionContext);

    /**
     * 取消扣款
     *
     */
    boolean cancel(BusinessActionContext businessActionContext);

}
